
const ls = {
  getItem(key: string){
    let result = localStorage.getItem(key);
    if(result && typeof result == 'string' && (result.indexOf("\"") >= 0 || result.indexOf("\[") >= 0)){
      try {
        result = JSON.parse(result);
      } catch (error) {
        console.log('LS getItem', error);
      }
    }
    return result;
  },
  setItem(key: string, value: any){
    return localStorage.setItem(key, JSON.stringify(value))
  },
  removeItem(key: string){
    return localStorage.removeItem(key)
  },
  clear(){
    return localStorage.clear()
  },
  key(index: number){
    return localStorage.key(index)
  },
}

export default ls